
/**
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file uiproxy.h
 * @author Marco Buzzanca 
 *
 * This header file contains UIProxy class declaration.
 */

#ifndef _UIPROXY_H_
#define _UIPROXY_H_ 1

#include <boost/cstdint.hpp>
#include <boost/filesystem.hpp>
#include <sstream>
#include <stdio.h>
#include "taskdescriptor.h"
#include "udpclient.h"
#include "address.h"

/**
 * @brief User interface proxy class.
 *
 * Provides methods for remote requests of executable files' transfer.
 */
class UIProxy
{
private:
    /**
    * @brief It will behave as a client, so we need an UDPClient object.
    */
    UDPClient _client;

public:
    /**
    * @brief Default Constructor.
    */
    UIProxy();

    /**
    * @brief Constructor specifying UI address.
    * @param UI_address the provided UI address.
    */
    UIProxy(const Address& UI_address);

    /**
    * @brief Constructor specifying UI IP and port.
    * @param UI_IP   The provided UI IP address.
    * @param UI_port The provided UI port.
    */
    UIProxy(const std::string& UI_IP, boost::uint16_t UI_port);

    /**
    * @brief Destructor.
    */
    ~UIProxy(void);

    /**
    * @brief Gets UI address.
    * @return UI address.
    */
    const Address& getUIAddress() const;

    /**
    * @brief Sets UI address using provided Address.
    * @param UI_address The provided address.
    */
    void setUIAddress(const Address& UI_address);

    /**
    * @brief Sets UI address using provided IP and port.
    * @param UI_IP    The provided IP address.
    * @param UI_port  The provided port.
    */
    void setUIAddress(const std::string& UI_IP, boost::uint16_t UI_port);

    /**
    * @brief Remotely asks UI node for executable filename included into
    *        provided TaskDescriptor and returns local file location.
    *
    * @param td The provided TaskDescriptor.
    *
    * @note it effectively calls this->getFile(td.getLink());
    */
    std::string getFile(const TaskDescriptor& td);

    /**
    * @brief Remotely asks UI node for provided executable filename and returns
    *        local file location.
    *
    * @param link The link to file in the system needed to execute the current task.
    */
    std::string getFile(const std::string& link);
};

#endif /* _UIPROXY_H_ */
